﻿<UserControl x:Class="F5.BigIp.LocalTrafficManager.UI.Views.ToolBarControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:F5.BigIp.LocalTrafficManager.UI.ViewModels"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             mc:Ignorable="d"
             d:DesignHeight="100" d:DesignWidth="800">

    <UserControl.DataContext>
        <local:MainViewModel/>
    </UserControl.DataContext>

    
    <UserControl.Resources>
        <Image x:Key="AddIcon" Source="../Resources/action_add_16xMD.png" />
        <Image x:Key="RemoveIcon" Source="../Resources/action_Cancel_16xMD.png" />
        
        <!--<Style x:Key="ConnectionToggleImageStyle" TargetType="ToggleButton">
            <Style.Triggers>
                <Trigger Property="IsChecked" Value="True">
                    <Setter Property="Content" Value="{StaticResource DisconnectImage}" />
                    <Setter Property="ToolTip" Value="Disconnect" />
                </Trigger>
                <Trigger Property="IsChecked" Value="False">
                    <Setter Property="Content" Value="{StaticResource ConnectImage}" />
                    <Setter Property="ToolTip" Value="Connect" />
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="DevicesComboBoxStyle" TargetType="ComboBox">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsConnected}" Value="True">
                    <Setter Property="IsEnabled" Value="False" />
                </DataTrigger>
                <DataTrigger Binding="{Binding IsConnected}" Value="False">
                    <Setter Property="IsEnabled" Value="True" />
                </DataTrigger>
            </Style.Triggers>
        </Style>-->
    </UserControl.Resources>

    <ToolBarTray>

        <ToolBarTray.Resources>
            <Style TargetType="TextBlock">
                <Setter Property="Margin" Value="5"/>
                <Setter Property="VerticalAlignment" Value="Center" />
            </Style>
            <Style TargetType="Image">
                <Setter Property="Width" Value="16"/>
                <Setter Property="Height" Value="16"/>
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Opacity" Value="0.2" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </ToolBarTray.Resources>

        <ToolBar>
            <ComboBox x:Name="Devices" 
                      ItemsSource="{Binding LoadBalancers}" 
                      SelectedItem="{Binding SelectedLoadBalancer}" 
                      DisplayMemberPath="Host" 
                      IsReadOnly="True"
                      IsEditable="True"
                      Width="100"
                      Text="Select LoadBalancer..."
                      TabIndex="0">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                        <i:InvokeCommandAction Command="{Binding LoadPoolsCommand}" CommandParameter="{Binding SelectedLoadBalancer}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </ComboBox>
            
            
            
            <Button Content="{StaticResource AddIcon}" 
                    Command="{Binding AddDeviceCommand}"/>

            <Button Content="{StaticResource RemoveIcon}" 
                    Command="{Binding RemoveDeviceCommand}" 
                    CommandParameter="{Binding SelectedLoadBalancer}" />

        </ToolBar>

        <ToolBar>

            <ToolBar.Style>
                <Style TargetType="ToolBar">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding SelectedPoolMembers}" Value="{x:Null}">
                            <Setter Property="Visibility" Value="Hidden"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding SelectedPoolMembers.Count}" Value="0">
                            <Setter Property="Visibility" Value="Hidden"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ToolBar.Style>

            <Button CommandParameter="{Binding SelectedPoolMembers}" 
                    Command="{Binding EnableCommand}" 
                    ToolTip="Enable (All traffic allowed)">
                <Image Source="/F5.BigIp.LocalTrafficManager.UI;component/Resources/play.png"/>
            </Button>

            <Button CommandParameter="{Binding SelectedPoolMembers}" 
                    Command="{Binding DisableCommand}" 
                    ToolTip="Disable (Only persistent or active connections allowed)">
                <Image Source="/F5.BigIp.LocalTrafficManager.UI;component/Resources/pause.png"/>
            </Button>

            <Button CommandParameter="{Binding SelectedPoolMembers}" 
                    Command="{Binding ForceOfflineCommand}" 
                    ToolTip="Force Offline (Only active connections allowed)">
                <Image Source="/F5.BigIp.LocalTrafficManager.UI;component/Resources/stop.png"/>
            </Button>

        </ToolBar>

    </ToolBarTray>

</UserControl>
